home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / htmlparser / nsIParser.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  17KB  |  422 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37. #ifndef NS_IPARSER___
  38. #define NS_IPARSER___
  39.  
  40.  
  41. /**
  42.  * MODULE NOTES:
  43.  * @update  gess 4/1/98
  44.  *  
  45.  *  This class defines the iparser interface. This XPCOM
  46.  *  inteface is all that parser clients ever need to see.
  47.  *
  48.  **/
  49.  
  50. #include "nsISupports.h"
  51. #include "nsIStreamListener.h"
  52. #include "nsIDTD.h"
  53. #include "nsIInputStream.h"
  54. #include "nsHashtable.h"
  55. #include "nsVoidArray.h"
  56.  
  57. // {22039D29-2798-4412-9EA6-A11B41BA27D0}
  58. #define NS_IPARSER_IID      \
  59. { 0x22039d29, 0x2798, 0x4412, \
  60. { 0x9e, 0xa6, 0xa1, 0x1b, 0x41, 0xba, 0x27, 0xd0 } }
  61.  
  62. // {41421C60-310A-11d4-816F-000064657374}
  63. #define NS_IDEBUG_DUMP_CONTENT_IID \
  64. { 0x41421c60, 0x310a, 0x11d4, \
  65. { 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
  66.  
  67. class nsIContentSink;
  68. class nsIRequestObserver;
  69. class nsIParserFilter;
  70. class nsString;
  71. class nsIURI;
  72. class nsIChannel;
  73.  
  74. enum eParserCommands {
  75.   eViewNormal,
  76.   eViewSource,
  77.   eViewFragment,
  78.   eViewErrors
  79. };
  80.  
  81. enum eCRCQuality {
  82.   eCRCGood = 0,
  83.   eCRCFair,
  84.   eCRCPoor
  85. };
  86.  
  87.  
  88. enum eParserDocType {
  89.   ePlainText = 0,
  90.   eXML,
  91.   eHTML_Quirks,
  92.   eHTML3_Quirks, // separate, for editor output, since HTML pre-4.0 lacks tbody
  93.   eHTML_Strict
  94. };
  95.  
  96.  
  97. // define Charset source constants
  98. // note: the value order defines the priority; higher numbers take priority
  99. #define kCharsetUninitialized           0
  100. #define kCharsetFromWeakDocTypeDefault  1
  101. #define kCharsetFromUserDefault         2
  102. #define kCharsetFromDocTypeDefault      3
  103. #define kCharsetFromCache               4
  104. #define kCharsetFromParentFrame         5
  105. #define kCharsetFromBookmarks           6
  106. #define kCharsetFromAutoDetection       7
  107. #define kCharsetFromHintPrevDoc         8
  108. #define kCharsetFromMetaTag             9
  109. #define kCharsetFromByteOrderMark      10
  110. #define kCharsetFromChannel            11 
  111. #define kCharsetFromOtherComponent     12
  112. // Levels below here will be forced onto childframes too
  113. #define kCharsetFromParentForced       13
  114. #define kCharsetFromUserForced         14
  115. #define kCharsetFromPreviousLoading    15
  116.  
  117. enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
  118.  
  119. /** 
  120.  *  FOR DEBUG PURPOSE ONLY
  121.  *
  122.  *  Use this interface to query objects that contain content information.
  123.  *  Ex. Parser can trigger dump content by querying the sink that has
  124.  *      access to the content.
  125.  *  
  126.  *  @update  harishd 05/25/00
  127.  */
  128. class nsIDebugDumpContent : public nsISupports {
  129. public:
  130.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDEBUG_DUMP_CONTENT_IID)
  131.   NS_IMETHOD DumpContentModel()=0;
  132. };
  133.  
  134. /**
  135.  *  This class defines the iparser interface. This XPCOM
  136.  *  inteface is all that parser clients ever need to see.
  137.  *  
  138.  *  @update  gess 3/25/98
  139.  */
  140. class nsIParser : public nsISupports {
  141.   public:
  142.  
  143.     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
  144.  
  145.     /**
  146.      *  Call this method if you have a DTD that you want to share with the parser.
  147.        *  Registered DTD's get remembered until the system shuts down.
  148.      *  
  149.      *  @update  gess 3/25/98
  150.      *  @param   aDTD -- ptr DTD that you're publishing the services of
  151.      */
  152.     NS_IMETHOD RegisterDTD(nsIDTD* aDTD)=0;
  153.  
  154.  
  155.     /**
  156.      * Select given content sink into parser for parser output
  157.      * @update    gess5/11/98
  158.      * @param   aSink is the new sink to be used by parser
  159.      * @return  
  160.      */
  161.     NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
  162.  
  163.  
  164.     /**
  165.      * retrieve the sink set into the parser 
  166.      * @update    gess5/11/98
  167.      * @return  current sink
  168.      */
  169.     NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
  170.  
  171.     /**
  172.      *  Call this method once you've created a parser, and want to instruct it
  173.        *  about the command which caused the parser to be constructed. For example,
  174.      *  this allows us to select a DTD which can do, say, view-source.
  175.      *  
  176.      *  @update  gess 3/25/98
  177.      *  @param   aCommand -- ptrs to string that contains command
  178.      *  @return     nada
  179.      */
  180.     NS_IMETHOD_(void) GetCommand(nsCString& aCommand)=0;
  181.     NS_IMETHOD_(void) SetCommand(const char* aCommand)=0;
  182.     NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0;
  183.  
  184.     /**
  185.      *  Call this method once you've created a parser, and want to instruct it
  186.      *  about what charset to load
  187.      *  
  188.      *  @update  ftang 4/23/99
  189.      *  @param   aCharset- the charest of a document
  190.      *  @param   aCharsetSource- the soure of the chares
  191.      *  @return     nada
  192.      */
  193.     NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource)=0;
  194.     NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, PRInt32& oSource)=0;
  195.  
  196.     NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter) = 0;
  197.  
  198.     /** 
  199.      * Get the channel associated with this parser
  200.      * @update harishd,gagan 07/17/01
  201.      * @param aChannel out param that will contain the result
  202.      * @return NS_OK if successful
  203.      */
  204.     NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0;
  205.  
  206.     /** 
  207.      * Get the DTD associated with this parser
  208.      * @update vidur 9/29/99
  209.      * @param aDTD out param that will contain the result
  210.      * @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
  211.      */
  212.     NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;
  213.  
  214.     /******************************************************************************************
  215.      *  Parse methods always begin with an input source, and perform conversions 
  216.      *  until you wind up being emitted to the given contentsink (which may or may not
  217.      *  be a proxy for the NGLayout content model).
  218.      ******************************************************************************************/
  219.     
  220.     // Call this method to resume the parser from the blocked state.
  221.     NS_IMETHOD ContinueParsing() = 0;
  222.  
  223.     // Call this method to resume the parser from an unblocked state.
  224.     // This can happen, for example, if parsing was interrupted and then the
  225.     // consumer needed to restart the parser without waiting for more data.
  226.     // This also happens after loading scripts, which unblock the parser in
  227.     // order to process the output of document.write() and then need to
  228.     // continue on with the page load on an enabled parser.
  229.     NS_IMETHOD ContinueInterruptedParsing() = 0;
  230.     
  231.     // Stops parsing temporarily.
  232.     NS_IMETHOD_(void) BlockParser() = 0;
  233.     
  234.     // Open up the parser for tokenization, building up content 
  235.     // model..etc. However, this method does not resume parsing 
  236.     // automatically. It's the callers' responsibility to restart
  237.     // the parsing engine.
  238.     NS_IMETHOD_(void) UnblockParser() = 0;
  239.  
  240.     NS_IMETHOD_(PRBool) IsParserEnabled() = 0;
  241.     NS_IMETHOD_(PRBool) IsComplete() = 0;
  242.     
  243.     NS_IMETHOD Parse(nsIURI* aURL,
  244.                      nsIRequestObserver* aListener = nsnull,
  245.                      PRBool aEnableVerify = PR_FALSE,
  246.                      void* aKey = 0,
  247.                      nsDTDMode aMode = eDTDMode_autodetect) = 0;
  248.     NS_IMETHOD Parse(nsIInputStream* aStream,
  249.                      const nsACString& aMimeType,
  250.                      PRBool aEnableVerify = PR_FALSE,
  251.                      void* aKey = 0,
  252.                      nsDTDMode aMode = eDTDMode_autodetect) = 0;
  253.     NS_IMETHOD Parse(const nsAString& aSourceBuffer,
  254.                      void* aKey,
  255.                      const nsACString& aMimeType,
  256.                      PRBool aEnableVerify,
  257.                      PRBool aLastCall,
  258.                      nsDTDMode aMode = eDTDMode_autodetect) = 0;
  259.     
  260.     NS_IMETHOD Terminate(void) = 0;
  261.  
  262.     /**
  263.      * This method gets called when you want to parse a fragment of HTML or XML
  264.      * surrounded by the context |aTagStack|. It requires that the parser have
  265.      * been given a fragment content sink.
  266.      *
  267.      * @param aSourceBuffer The XML or HTML that hasn't been parsed yet.
  268.      * @param aKey The key used by the parser.
  269.      * @param aTagStack The context of the source buffer.
  270.      * @param aXMLMode Whether this is XML or HTML
  271.      * @param aContentType The content-type of this document.
  272.      * @param aMode The DTDMode that the parser should parse this fragment in.
  273.      * @return Success or failure.
  274.      */
  275.     NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
  276.                              void* aKey,
  277.                              nsVoidArray& aTagStack,
  278.                              PRBool aXMLMode,
  279.                              const nsACString& aContentType,
  280.                              nsDTDMode aMode = eDTDMode_autodetect) = 0;
  281.  
  282.     /**
  283.      * This method gets called when the tokens have been consumed, and it's time
  284.      * to build the model via the content sink.
  285.      * @update    gess5/11/98
  286.      * @return  error code -- 0 if model building went well .
  287.      */
  288.     NS_IMETHOD BuildModel(void) = 0;
  289.  
  290.  
  291.     /**
  292.      *  Retrieve the parse mode from the parser...
  293.      *  
  294.      *  @update  gess 6/9/98
  295.      *  @return  ptr to scanner
  296.      */
  297.     NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0;
  298.  
  299.     /**
  300.      *  Call this method to cancel any pending parsing events.
  301.      *  Parsing events may be pending if all of the document's content
  302.      *  has been passed to the parser but the parser has been interrupted
  303.      *  because processing the tokens took too long.
  304.      *  
  305.      *  @update  kmcclusk 05/18/01
  306.      *  @return  NS_OK if succeeded else ERROR.
  307.      */
  308.  
  309.     NS_IMETHOD CancelParsingEvents() = 0;
  310. };
  311.  
  312. /* ===========================================================*
  313.   Some useful constants...
  314.  * ===========================================================*/
  315.  
  316. #include "prtypes.h"
  317. #include "nsError.h"
  318.  
  319. #define NS_ERROR_HTMLPARSER_EOF                            NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1000)
  320. #define NS_ERROR_HTMLPARSER_UNKNOWN                        NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1001)
  321. #define NS_ERROR_HTMLPARSER_CANTPROPAGATE                  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1002)
  322. #define NS_ERROR_HTMLPARSER_CONTEXTMISMATCH                NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1003)
  323. #define NS_ERROR_HTMLPARSER_BADFILENAME                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1004)
  324. #define NS_ERROR_HTMLPARSER_BADURL                         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1005)
  325. #define NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT           NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1006)
  326. #define NS_ERROR_HTMLPARSER_INTERRUPTED                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
  327. #define NS_ERROR_HTMLPARSER_BLOCK                          NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
  328. #define NS_ERROR_HTMLPARSER_BADTOKENIZER                   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009)
  329. #define NS_ERROR_HTMLPARSER_BADATTRIBUTE                   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010)
  330. #define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD                  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1011)
  331. #define NS_ERROR_HTMLPARSER_MISPLACEDTABLECONTENT          NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1012)
  332. #define NS_ERROR_HTMLPARSER_BADDTD                         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1013)
  333. #define NS_ERROR_HTMLPARSER_BADCONTEXT                     NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1014)
  334. #define NS_ERROR_HTMLPARSER_STOPPARSING                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1015)
  335. #define NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL      NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1016)
  336. #define NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP               NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1017)
  337. #define NS_ERROR_HTMLPARSER_FAKE_ENDTAG                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1018)
  338. #define NS_ERROR_HTMLPARSER_INVALID_COMMENT                NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1019)
  339.  
  340. #define NS_ERROR_HTMLPARSER_CONTINUE              NS_OK
  341.  
  342.  
  343. const PRUint32  kEOF              = NS_ERROR_HTMLPARSER_EOF;
  344. const PRUint32  kUnknownError     = NS_ERROR_HTMLPARSER_UNKNOWN;
  345. const PRUint32  kCantPropagate    = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
  346. const PRUint32  kContextMismatch  = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
  347. const PRUint32  kBadFilename      = NS_ERROR_HTMLPARSER_BADFILENAME;
  348. const PRUint32  kBadURL           = NS_ERROR_HTMLPARSER_BADURL;
  349. const PRUint32  kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
  350. const PRUint32  kBlocked          = NS_ERROR_HTMLPARSER_BLOCK;
  351. const PRUint32  kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
  352. const PRUint32  kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
  353. const PRUint32  kFakeEndTag       = NS_ERROR_HTMLPARSER_FAKE_ENDTAG;
  354. const PRUint32  kNotAComment      = NS_ERROR_HTMLPARSER_INVALID_COMMENT;
  355.  
  356. const PRUnichar  kNewLine          = '\n';
  357. const PRUnichar  kCR               = '\r';
  358. const PRUnichar  kLF               = '\n';
  359. const PRUnichar  kTab              = '\t';
  360. const PRUnichar  kSpace            = ' ';
  361. const PRUnichar  kQuote            = '"';
  362. const PRUnichar  kApostrophe       = '\'';
  363. const PRUnichar  kLessThan         = '<';
  364. const PRUnichar  kGreaterThan      = '>';
  365. const PRUnichar  kAmpersand        = '&';
  366. const PRUnichar  kForwardSlash     = '/';
  367. const PRUnichar  kBackSlash        = '\\';
  368. const PRUnichar  kEqual            = '=';
  369. const PRUnichar  kMinus            = '-';
  370. const PRUnichar  kPlus             = '+';
  371. const PRUnichar  kExclamation      = '!';
  372. const PRUnichar  kSemicolon        = ';';
  373. const PRUnichar  kHashsign         = '#';
  374. const PRUnichar  kAsterisk         = '*';
  375. const PRUnichar  kUnderbar         = '_';
  376. const PRUnichar  kComma            = ',';
  377. const PRUnichar  kLeftParen        = '(';
  378. const PRUnichar  kRightParen       = ')';
  379. const PRUnichar  kLeftBrace        = '{';
  380. const PRUnichar  kRightBrace       = '}';
  381. const PRUnichar  kQuestionMark     = '?';
  382. const PRUnichar  kLeftSquareBracket  = '[';
  383. const PRUnichar  kRightSquareBracket = ']';
  384. const PRUnichar kNullCh           = '\0';
  385.  
  386. // XXXbz these type defines should really just go away....  Until they
  387. // do, changes here should be reflected in nsContentDLF.cpp
  388. #define kHTMLTextContentType  "text/html"
  389. #define kXMLTextContentType   "text/xml"
  390. #define kXMLApplicationContentType "application/xml"
  391. #define kXHTMLApplicationContentType "application/xhtml+xml"
  392. #define kXULTextContentType   "application/vnd.mozilla.xul+xml"
  393. #define kRDFTextContentType   "text/rdf"
  394. #define kRDFApplicationContentType "application/rdf+xml"
  395. #define kXIFTextContentType   "text/xif"
  396. #define kPlainTextContentType "text/plain"
  397. #define kViewSourceCommand    "view-source"
  398. #define kViewFragmentCommand  "view-fragment"
  399. #define kTextCSSContentType   "text/css"
  400. #define kApplicationJSContentType "application/javascript"
  401. #define kApplicationXJSContentType "application/x-javascript"
  402. #define kTextECMAScriptContentType "text/ecmascript"
  403. #define kApplicationECMAScriptContentType "application/ecmascript"
  404. #define kTextJSContentType    "text/javascript"
  405. #define kSGMLTextContentType   "text/sgml"
  406. #define kSVGTextContentType   "image/svg+xml"
  407.  
  408. #define NS_IPARSER_FLAG_UNKNOWN_MODE         0x00000000
  409. #define NS_IPARSER_FLAG_QUIRKS_MODE          0x00000002
  410. #define NS_IPARSER_FLAG_STRICT_MODE          0x00000004
  411. #define NS_IPARSER_FLAG_AUTO_DETECT_MODE     0x00000010
  412. #define NS_IPARSER_FLAG_VIEW_NORMAL          0x00000020
  413. #define NS_IPARSER_FLAG_VIEW_SOURCE          0x00000040
  414. #define NS_IPARSER_FLAG_VIEW_ERRORS          0x00000080
  415. #define NS_IPARSER_FLAG_PLAIN_TEXT           0x00000100
  416. #define NS_IPARSER_FLAG_XML                  0x00000200
  417. #define NS_IPARSER_FLAG_HTML                 0x00000400
  418. #define NS_IPARSER_FLAG_SCRIPT_ENABLED       0x00000800
  419. #define NS_IPARSER_FLAG_FRAMES_ENABLED       0x00001000
  420.  
  421. #endif 
  422.